import { createRouter, createWebHistory } from "vue-router";
import type { RouteRecordRaw } from "vue-router";

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: "/index",
    name: "index",
    component: () => import("@/pages/index.vue"),
    redirect: "/dashboard",
    children: [
      {
        path: "/dashboard",
        name: "dashboard",
        component: () => import("@/pages/dashboard/dashboard.vue")
      },
      {
        path: "/followtrend",
        name: "followtrend",
        component: () => import("@/pages/followtrend/followtrend.vue")
      },
      {
        path: "/message",
        name: "message",
        component: () => import("@/pages/message/message.vue")
      },
      {
        path: "/push",
        name: "push",
        component: () => import("@/pages/push/push.vue")
      },
      {
        path: "/user",
        name: "user",
        component: () => import("@/pages/user/user.vue")
      }
    ]
  },
  {
    path: "/article/:id",
    name: "article",
    component: () => import("@/pages/article.vue"),
    props: (route) => ({
      id: Number(route.params.id)  // 正确获取params并转换为Number
    })
  },
  {
    path: "/test",
    name: "test",
    component: () => import("@/pages/test.vue"),
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

export default router